package ControlLayer;




import java.util.ArrayList;

import ModelLayer.SalesRecords;
import ModelLayer.Sale;
import ModelLayer.RealException;
import ModelLayer.SalesLine;;



public class SalesCtr {
	
	private SalesRecords salesRecords;
	private PersonCtr personCtr;
	
	public SalesCtr() 
	{
		salesRecords = SalesRecords.getInstance();
		personCtr = new PersonCtr();
	}
	
	public Sale getSales(int id) throws RealException
	{
		return salesRecords.getSale(id);
	}
	
	public Sale getOffer(int id) throws RealException
	{
		return salesRecords.getOffer(id);
	}
	
	public Sale getOrder(int id) throws RealException
	{
		return salesRecords.getOrder(id);
	}
	
	
	
	public void removeSales(int id) throws RealException
	{
		salesRecords.removeSale(id);
	}
	
	public void updateSales(int id, int choise, String value) throws RealException
	{
		salesRecords.updateSale(id, choise, value);
	}
	
	public void updateOfferSalelines(int offerId, ArrayList<SalesLine> salelines) throws RealException {
		getOffer(offerId).setSaleLines(salelines);
	}
	
	public int createOffer(int customerId, int employeeId, long startDate) throws RealException
	{
		
		return salesRecords.createSale(customerId, employeeId, startDate);
	}
	
	public void setOfferInfo(int offerId, int customerId, int employeeId, long date) throws RealException 
	{
		Sale offer = salesRecords.getOffer(offerId);
		offer.setCustomer(personCtr.getCustomer(customerId));
		offer.setEmployee(personCtr.getEmployee(employeeId));
		offer.setDate(date);
	}
	
	
	public double getSalePrice(int id) throws RealException
	{
		return salesRecords.getSale(id).getFinalPrice();
	}
	
	public String printSales(int id) throws RealException
	{
		return salesRecords.getSale(id).toString();
	}
	
	public void confirmOffer(int id) throws RealException
	{
		salesRecords.getSale(id).confirmOffer();
	}
	
	public void confirmPayment(int id) throws RealException
	{
		salesRecords.getSale(id).confirmPayment();
	}
	
	public void hasPickup(int id) throws RealException
	{
		salesRecords.getSale(id).setPickup(true);
	}
	
	public void noPickup(int id, String address) throws RealException
	{
		salesRecords.getSale(id).setPickup(false);
		salesRecords.getSale(id).setdAddress(address);
	}
	
	public void addSalesLine(int saleId, int quantity, String barcode) throws RealException
	{
		salesRecords.getSale(saleId).addSalesLine(quantity, barcode);
	}
	
	public void removeSalesLine(int saleId, String barcode) throws RealException
	{
		salesRecords.getSale(saleId).removeSalesLine(barcode);
	}
	
	public String getSalelineInfo(int saleId, String barcode) throws RealException
	{
		return salesRecords.getSale(saleId).getSalesLine(barcode).toString();
	}
	
	
	
	public String listAllOffer()
	{
		return salesRecords.printAllOfferInfo();
	}
	
	public String listAllOrder()
	{
		return salesRecords.printAllOrderInfo();
	}
	
	
	
}
